package com.flyee.controller.tools.monster.control
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class CutMananger
	{
		public function CutMananger()
		{
		}
		public static function cutBitmapData(source:BitmapData,width:Number = 130,height:Number = 103):Array
		{
			var tempBitmap:Bitmap = new Bitmap(source)
			var tempArray:Array = cut(tempBitmap,width,height);
			return tempArray;
		}
		public static function cut(source:DisplayObject,width:Number = 130,height:Number = 103):Array
		{
			var tempFrame:Number = Math.round(source.width / width );
			var tempDir:Number = Math.round(source.height / height);
			
			//获取源数据
			var tempBitmapData:BitmapData = new BitmapData(source.width,source.height,true,0);
			tempBitmapData.draw(source);
			
			//创建裁剪框
			var rect:Rectangle = new Rectangle(0,0,width,height);
			var copyPoint:Point = new Point(0,0);
		
			//创建2维数组
			var tempAppearanceArray:Array = new Array();
			//开始裁剪
			for (var i:int =0; i< tempDir; i++)
			{
				//创建2维数组
				var tempArray:Array = new Array ();
				for (var j:int =0; j< tempFrame; j++)
				{
					//创建1维数组
					var tempBitmapData2:BitmapData = new BitmapData(width,height,true,0);
					
					rect.x = j * width;
					rect.y = i * height;
					tempBitmapData2.copyPixels(tempBitmapData,rect,copyPoint);
					tempArray[j] = new Bitmap(tempBitmapData2)
				}
				tempAppearanceArray[i] = tempArray;
			}
			return tempAppearanceArray;
		}
	}
}